//
//  mainViewController.m
//  blackjack
//
//  Created by Thi Nguyen Tran on 3/13/10.
//  Copyright 2010 Epsilon. All rights reserved.
//

#import "mainViewController.h"
#import "CardcountingMainController.h"
#import "TutorViewController.h"
#import "BasicStrategyViewController.h"
#import "InforViewController.h"
#import "constants.h"

#define DEBUG_LOADING

@implementation MainViewController

-(id)init {
	if(self = [super init]) {
		CGRect frame = CGRectMake(0, 0, 320, 480);
#ifdef DEBUG_LOADING			
		loading_ = [[LoadingView alloc] initWithFrame:frame];
		[loading_ setDelegate:self];		
		self.view = loading_;
		
#elif DEBUG_MAIN_MENU
		menus_   = [[MainMenu alloc] initWithFrame:frame];
		[menus_ setDelegate:self];
		self.view = menus_;
		
#elif DEBUG_CARDCOUNTING
		countingController_ = [[CardcountingMainController alloc] init];
		self.view = countingController_.view;
		
#elif DEBUG_TUTORIAL
		tutorController_ = [[TutorViewController alloc] init];
		self.view = tutorController_.view;
		
#elif DEBUG_BASIC_STRATEGY
		basicController_ = [[BasicStrategyViewController alloc] init];
		self.view = basicController_.view;
#endif

	}
	return self;
}

- (void)touchedLoadingView
{
	if(!menus_) {
		menus_ = [[MainMenu alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
		menus_.delegate = self;
	}
	
	self.view = menus_;
	[loading_ release];
}

- (void)reloadMainMenu {
	if(!menus_) {
		menus_ = [[MainMenu alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
		menus_.delegate = self;
	}
	
	self.view = menus_;
	if(controller_)
		[controller_ release];
}

- (void)chooseMode:(int)m {
	if(controller_ != nil) {
		[controller_ release];
	}
	switch (m) {
		case BASIC_STRATEGY:
			controller_ = [[BasicStrategyViewController alloc] init];
			break;
		case TUTORIAL_AND_TIPS:
			controller_ = [[TutorViewController alloc] init];
			break;
		case CARD_COUNTING:
			controller_ = [[CardcountingMainController alloc] init];
			break;
		case INFORMATION:
			controller_ = [[InforViewController alloc] init];
			break;
		default:
			break;
	}
	self.view = controller_.view;
}

- (void)exitApp {
	// terminate application intermediately 
}


// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
	
}



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
